#include <iostream>
#include "MyArray.h"

void printArray(const MyArray& arr, const std::string& name) {
    std::cout << name << "（长度：" << arr.getSize() << "）：";
    for (int i = 0; i < arr.getSize(); ++i) {
        std::cout << arr[i] << " ";
    }
    std::cout << std::endl;
}

int main() {
    MyArray arr1;                  
    MyArray arr2(5);               
    for (int i = 0; i < arr2.getSize(); ++i) {
        arr2[i] = i + 1;         
    }
    printArray(arr1, "arr1（默认构造）");
    printArray(arr2, "arr2（带参构造+赋值）");

    MyArray arr3(arr2);            
    arr3[2] = 99;
    printArray(arr2, "arr2（拷贝后未修改）"); 
    printArray(arr3, "arr3（拷贝构造+修改）");

    MyArray arr4;
    arr4 = arr2;                   
    arr4[4] = 88;                 
    printArray(arr2, "arr2（赋值后未修改）");
    printArray(arr4, "arr4（赋值运算+修改）");

    MyArray arr5(3);
    arr5[0] = 10; arr5[1] = 20; arr5[2] = 30;
    MyArray arr6(2);
    arr6[0] = 40; arr6[1] = 50;
    MyArray merged1 = arr5.merge(arr6);
    MyArray merged2 = arr1.merge(arr2); 
    printArray(arr5, "arr5（合并源1）");
    printArray(arr6, "arr6（合并源2）");
    printArray(merged1, "merged1（arr5+arr6）");
    printArray(merged2, "merged2（空数组+arr2）");

    MyArray a(3); a[0] = 1; a[1] = 2; a[2] = 3;
    MyArray b(2); b[0] = 4; b[1] = 5;
    printArray(a, "a（运算源1）");
    printArray(b, "b（运算源2）");

    MyArray sum = a.add(b);
    MyArray diff = a.subtract(b);
    MyArray prod = a.multiply(b);
    MyArray quot = a.divide(b);

    printArray(sum, "a + b");     
    printArray(diff, "a - b");     
    printArray(prod, "a * b");    
    printArray(quot, "a / b");     

    MyArray c(1); c[0] = 5;
    MyArray d(1); d[0] = 0;
    std::cout << "\n边界测试（除数为0）：" << std::endl;
    MyArray quot2 = c.divide(d);
    printArray(quot2, "c / d");

    return 0;
}